home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / Math.cls < prev    next >
Text File  |  1997-06-14  |  3KB  |  143 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "GMath"
  6. Attribute VB_GlobalNameSpace = True
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Option Explicit
  11.  
  12. Public Enum EErrorMath
  13.     eeBaseMath = 13520      ' Math
  14. End Enum
  15.  
  16. ' Derived math functions from language reference Appendix D
  17.  
  18. ' Secant
  19. Function Sec(x As Double) As Double
  20.     Sec = 1 / Cos(x)
  21. End Function
  22.  
  23. ' Cosecant
  24. Function CoSec(x As Double) As Double
  25.     CoSec = 1 / Sin(x)
  26. End Function
  27.  
  28. ' Cotangent
  29. Function CoTan(x As Double) As Double
  30.     CoTan = 1 / Tan(x)
  31. End Function
  32.  
  33. ' Inverse Sine
  34. Function ArcSin(x As Double) As Double
  35.     ArcSin = Atn(x / Sqr(-x * x + 1))
  36. End Function
  37.  
  38. ' Inverse Cosine
  39. Function ArcCos(x As Double) As Double
  40.     ArcCos = Atn(-x / Sqr(-x * x + 1)) + 2 * Atn(1)
  41. End Function
  42.  
  43. ' Inverse Secant
  44. Function ArcSec(x As Double) As Double
  45.     ArcSec = Atn(x / Sqr(x * x - 1)) + Sgn(x - 1) * (2 * Atn(1))
  46. End Function
  47.  
  48. ' Inverse Cosecant
  49. Function ArcCoSec(x As Double) As Double
  50.     ArcCoSec = Atn(x / Sqr(x * x - 1)) + (Sgn(x) - 1) * (2 * Atn(1))
  51. End Function
  52.  
  53. ' Inverse Cotangent
  54. Function ArcCoTan(x As Double) As Double
  55.     ArcCoTan = Atn(x) + 2 * Atn(1)
  56. End Function
  57.  
  58. ' Hyperbolic Sine
  59. Function HSin(x As Double) As Double
  60.     HSin = (Exp(x) - Exp(-x)) / 2
  61. End Function
  62.  
  63. ' Hyperbolic Cosine
  64. Function HCos(x As Double) As Double
  65.     HCos = (Exp(x) + Exp(-x)) / 2
  66. End Function
  67.  
  68. ' Hyperbolic Tangent
  69. Function HTan(x As Double) As Double
  70.     HTan = (Exp(x) - Exp(-x)) / (Exp(x) + Exp(-x))
  71. End Function
  72.  
  73. ' Hyperbolic Secant
  74. Function HSec(x As Double) As Double
  75.     HSec = 2 / (Exp(x) + Exp(-x))
  76. End Function
  77.  
  78. ' Hyperbolic Cosecant
  79. Function HCoSec(x As Double) As Double
  80.     HCoSec = 2 / (Exp(x) - Exp(-x))
  81. End Function
  82.  
  83. ' Hyperbolic Cotangent
  84. Function HCotan(x As Double) As Double
  85.     HCotan = (Exp(x) + Exp(-x)) / (Exp(x) - Exp(-x))
  86. End Function
  87.  
  88. ' Inverse Hyperbolic Sine
  89. Function HArcSin(x As Double) As Double
  90.     HArcSin = Log(x + Sqr(x * x + 1))
  91. End Function
  92.  
  93. ' Inverse Hyperbolic Cosine
  94. Function HArcCos(x As Double) As Double
  95.     HArcCos = Log(x + Sqr(x * x - 1))
  96. End Function
  97.  
  98. ' Inverse Hyperbolic Tangent
  99. Function HArcTan(x As Double) As Double
  100.     HArcTan = Log((1 + x) / (1 - x)) / 2
  101. End Function
  102.  
  103. ' Inverse Hyperbolic Secant
  104. Function HArcSec(x As Double) As Double
  105.     HArcSec = Log((Sqr(-x * x + 1) + 1) / x)
  106. End Function
  107.  
  108. ' Inverse Hyperbolic Cosecant
  109. Function HArcCoSec(x As Double) As Double
  110.     HArcCoSec = Log((Sgn(x) * Sqr(x * x + 1) + 1) / x)
  111. End Function
  112.  
  113. ' Inverse Hyperbolic Cotangent
  114. Function HArcCoTan(x As Double) As Double
  115.     HArcCoTan = Log((x + 1) / (x - 1)) / 2
  116. End Function
  117.  
  118. ' Logarithm to base N
  119. Function LogN(x As Double, n As Double) As Double
  120.     LogN = Log(x) / Log(n)
  121. End Function
  122.  
  123. #If fComponent = 0 Then
  124. Private Sub ErrRaise(e As Long)
  125.     Dim sText As String, sSource As String
  126.     If e > 1000 Then
  127.         sSource = App.ExeName & ".Math"
  128.         Select Case e
  129.         Case eeBaseMath
  130.             BugAssert True
  131.        ' Case ee...
  132.        '     Add additional errors
  133.         End Select
  134.         Err.Raise COMError(e), sSource, sText
  135.     Else
  136.         ' Raise standard Visual Basic error
  137.         sSource = App.ExeName & ".VBError"
  138.         Err.Raise e, sSource
  139.     End If
  140. End Sub
  141. #End If
  142.  
  143.